import React, {Component} from 'react';
import {inject, observer} from 'mobx-react';
import * as mobx from 'mobx';
import {WeaScroll} from 'ecCom';
import FavDirBar from './FavDirBar';
import FavDirTree from './FavDirTree';
import '../../style/index.css';
import SearchFavourite from '../../util/SearchFavourite';


@inject('sysFavouriteStore', 'favouriteDirStore')

@observer
export default class FavouriteDir extends Component {
    constructor(props) {
        super(props);
    }

    onTreeNodeSelect = (nodeid) => {
        const {favouriteDirStore, sysFavouriteStore} = this.props;
        if (nodeid.indexOf('add') == -1 && nodeid.indexOf('edit') == -1) { // 非编辑状态下
            /**
             * 记录下选中的节点
             */
            favouriteDirStore.selectTreeNode(nodeid);
            /**
             * 选中树节点后，刷新收藏的列表
             */
            const isinit = true;
            const isreload = false;
            SearchFavourite.setConditions({dirId: nodeid});
            const searchFavourite = new SearchFavourite(sysFavouriteStore);
            searchFavourite.load({isinit, isreload});
        }
    }

    render() {
        return (
            <div className={this.props.changename == 'fullPagetreeLeft' ? 'fullPagetreeLeft' : 'fav-left'}>
                <FavDirBar ecId={`${this && this.props && this.props.ecId || ''}_FavDirBar@lwj582`}/>
                <div className="fav-left-tree">
                    <WeaScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaScroll@sy079h`}
                               className="sysfav-scroll-wrapper" typeClass="scrollbar-macosx" style={{width: '100%'}}>
                        <FavDirTree
                            ecId={`${this && this.props && this.props.ecId || ''}_FavDirTree@e4l8vl`}
                            onSelect={this.onTreeNodeSelect}/>
                    </WeaScroll>
                </div>
            </div>
        );
    }
}
